package com.nanyang.tms.controller.waybillreceipt;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.waybillreceipt.WaybillCustomerNoQueryRequest;
import com.nanyang.tms.api.dto.request.waybillreceipt.WaybillReceiptFeeQueryRequest;
import com.nanyang.tms.api.dto.request.waybillreceipt.WaybillReceiptQueryRequest;
import com.nanyang.tms.api.dto.request.waybillreceipt.WaybillReceiptTrackQueryRequest;
import com.nanyang.tms.api.dto.response.waybillreceipt.*;
import com.nanyang.tms.api.service.waybillreceipt.WaybillReceiptRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/waybillreceipt")
public class WaybillReceiptController {
    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private WaybillReceiptRpcService waybillReceiptRpcService;

    /**
     * <p>listWaybill</p>
     * <p>Description:前台-查询运单列表</p>
     *
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResult<PageBean<WaybillReceiptPageResponse>> list(@BindParam @RequestBody WaybillReceiptQueryRequest param) {
        ApiResult<PageBean<WaybillReceiptPageResponse>> apiResult = waybillReceiptRpcService.listWaybillReceipt(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 前台-查询费用
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/listFee", method = RequestMethod.POST)
    public ApiResult<PageBean<WaybillReceiptFeePageResponse>> listFee(@BindParam @RequestBody WaybillReceiptFeeQueryRequest param) {
        ApiResult<PageBean<WaybillReceiptFeePageResponse>> apiResult = waybillReceiptRpcService.listWaybillReceiptFee(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 前台-查询费用明细
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/listFeeDetail", method = RequestMethod.POST)
    public ApiResult<PageBean<WaybillReceiptFeeDetailResponse>> listFeeDetail(@BindParam @RequestBody WaybillReceiptFeeQueryRequest param) {
        ApiResult<PageBean<WaybillReceiptFeeDetailResponse>> apiResult = waybillReceiptRpcService.listWaybillReceiptFeeDetail(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 前台-查询运单详情
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    public ApiResult<WaybillBaseDetailResponse> detailWaybillReceipt(@BindParam @RequestBody WaybillCustomerNoQueryRequest param) {
        ApiResult<WaybillBaseDetailResponse> apiResult = waybillReceiptRpcService.detailWaybillReceipt(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * <p>listWaybill</p>
     * <p>Description:前台-查询轨迹列表</p>
     *
     * @param param
     * @return
     */
    @BindParam
    @RequestMapping(value = "/listTrack", method = RequestMethod.POST)
    public ApiResult<PageBean<WaybillReceiptTrackPageResponse>> list(@BindParam @RequestBody WaybillReceiptTrackQueryRequest param) {
        ApiResult<PageBean<WaybillReceiptTrackPageResponse>> apiResult = waybillReceiptRpcService.listWaybillReceiptTrack(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
}
